package com.briup.cms.dao;

import com.briup.cms.bean.Comment;
import com.briup.cms.bean.extend.CommentExtend;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CommentMapper {

//    @Results(
//            {
//                    @Result(column = "comment_date", property = "commentDate"),
//                    @Result(column = "article_id", property = "articleId"),
//                    @Result(column = "user_id", property = "userId"),
//                    @Result(column = "parent_id", property = "parentId")
//            }
//   )

    @Select("select * from cms_comment")
    List<Comment> selectAll();

    @Insert("insert into cms_comment values(null,#{content},#{comment_date},#{status},#{article_id},#{user_id},#{parent_id})")
    void insert(Comment comment);

    @Update("update cms_comment set content=#{content},comment_date=#{comment_date},status=#{status},article_id=#{article_id},user_id=#{user_id},parent_id=#{parent_id} where id=#{id}")
    void update(Comment comment);

    @Delete("delete from cms_comment where id=#{id}")
    void deleteById(long id);

    @Results({
            @Result(property = "articleId", column = "article_id"),
            @Result(property = "articleTitle", column = "article_title"),
            @Result(property = "userId", column = "user_id"),
            @Result(property = "userUserName", column = "user_username")
    })
    @Select("select c.*,a.title as article_title from cms_comment c left join cms_article a on c.article_id = a.id")
    List<CommentExtend> selectAllWithArticle();

    @Select("select c.*,u.username as user_username from cms_comment c left join cms_user u on c.user_id = u.id")
    List<CommentExtend> selectAllWithUser();

}
